
<?php if(isset($isInsert) && $isInsert){
?>
<script>
	ajax('listContent','<?php echo $this->params['controller']?>/lists');
	closeBox('addContent','mainContent');
</script>
<?php
}
else{
?>
<fieldset>
    <legend><?php _resource('edit task');?></legend>
<center><div id="message">&nbsp;</div></center>
<?php if($this->Session->read('message')){
	echo '<script>showMessage("addContent","'.$this->Session->read('message').'");</script>';
	$this->Session->delete('message');	
	}?>
<?php if($this->Session->read('error')){
	echo '<script>showMessage("addContent","'.$this->Session->read('error').'",1);</script>';
	$this->Session->delete('error');
}?>
    <form id="adminForm" name="adminForm" method="post" action="<?php echo $this->params['controller']?>/edit/<?php echo $this->data[$uses[0]]['id']?>" onsubmit="onFormSubmit();return false;">
    <?php
		echo $this->Form->hidden($uses[0].'.id');		
		echo $this->Form->hidden($uses[0].'.view_order');
		echo $this->Form->hidden($uses[0].'.published');		
		echo $this->Form->hidden($uses[0].'.user_id');	
		if(!Configure::read('Session.isSa') &&!Configure::read('Session.isAdmin') &&!Configure::read('Session.isManager'))echo $this->Form->hidden($uses[0].'.project_id');
	?>
	<table border="0" class="form" style="width:100%">
       	<tr>          
       		<td class="label" align="right" width="100px"><?php _resource('name') ?>
       		
       		</td>
       		<td align="left"><?php echo $this->Form->input($uses[0].'.name',array('class'=>'input','label'=>'','size'=>60,'maxlength'=>255));?></td>           
        </tr>      
		
		<tr>          
       		<td class="label" align="right" width="100px"><?php _resource('file attach') ?>
       		
       		</td>
       		<td align="left">
       		<div id="divUploadContainer" style="text-align: left">
       		<?php if(isset($this->data['FileAttach'])&& !empty($this->data['FileAttach'])){
       			foreach($this->data['FileAttach'] as $k=>$v){
       			?>
       			<div class="progressWrapper" id="fileUpload<?php echo $v['id']?>" style="opacity: 1;">
       				<div class="fileContainer">
       					<a href="<?php echo SITE_URL.'/uploaded/Task/document/'.$v['name']?>"><?php echo $v['name']?></a>
       					<?php if(isset($v['username']) && !empty($v['username'])){?>
       						<span style="color:#999">(<?php echo $v['username']?>)</span> 
       					<?php }?>
       					<span title="delete"><a href="javascript:;" onclick="removeFile('fileUpload<?php echo $v['id']?>')"> <img border="0" src="<?php echo SITE_URL?>/img/backend/publish_x.png"></a></span>
       				</div>
       				<input type="hidden" class="inputHidden" name="data[FileAttach][fileUpload<?php echo $v['id']?>][name]" value="<?php echo $v['name']?>">
       				<input type="hidden" class="inputHidden" name="data[FileAttach][fileUpload<?php echo $v['id']?>][id]" value="<?php echo $v['id']?>">
       				<input type="hidden" class="inputHidden" name="data[FileAttach][fileUpload<?php echo $v['id']?>][username]" value="<?php echo $v['username']?>">
       			</div>
       		<?php }}?>
       		</div>
       		<div style="width: 80px; height: 18px; border: solid 1px #7FAAFF; background-color: #C5D9FF; padding: 2px;">
					<span id="spanButtonPlaceholder"></span>
				</div>     
				<div class="fieldset flash" id="divFileProgressContainer"></div>      
        	</td>
        </tr>
        
        <tr>          
       		<td class="label" align="right" width="100px"><?php _resource('description') ?>
       		
       		</td>
       		<td align="left"><?php echo $this->Form->textarea($uses[0].'.description',array('class'=>'','label'=>'','error'=>'','cols'=>120,'rows'=>10));?></td>           
        </tr> 

<?php if(count($types)>0){?>
 	<tr>          
       		<td class="label" align="right" width="100px"><?php _resource('type') ?>
       		
       		</td>
       		<td align="left">
				<?php echo $this->Form->input($uses[0].'.type_id', array('type'=>'select','options'=>$types,'default'=>null,'empty'=>false,"class"=>"inputbox","label"=>"","error"=>""));?>       		

       		</td>           
        </tr>   
        <?php }?>

<?php if(count($statuses)>0){?>
 	<tr>          
       		<td class="label" align="right" width="100px"><?php _resource('status') ?>
       		
       		</td>
       		<td align="left">
       			<?php echo $this->Form->input($uses[0].'.status_id', array('type'=>'select','options'=>$statuses,'default'=>null,'empty'=>false,"class"=>"inputbox","label"=>"","error"=>""));?>
       		</td>           
        </tr>   
        <?php }?>
        
        <?php if(count($priors)>0){?>
 	<tr>          
       		<td class="label" align="right" width="100px"><?php _resource('priority') ?>
       		
       		</td>
       		<td align="left">
       		<?php echo $this->Form->input($uses[0].'.priority_id', array('type'=>'select','options'=>$priors,'default'=>null,'empty'=>false,"class"=>"inputbox","label"=>"","error"=>""));?>
       		
       		</td>           
        </tr>   
        <?php }?>
        <?php if(count($projects)>0 && (Configure::read('Session.isSa') ||Configure::read('Session.isAdmin') ||Configure::read('Session.isManager'))){?>
 	<tr>          
       		<td class="label" align="right" width="100px"><?php _resource('project') ?>
       		
       		</td>
       		<td align="left">
       		<?php echo $this->Form->input($uses[0].'.project_id', array('type'=>'select','options'=>$projects,'default'=>null,'empty'=>false,"class"=>"inputbox","label"=>"","error"=>""));?>
       			
       		</td>           
        </tr>   
        <?php }?>
        <?php if(isset($users)>0){?>
 	<tr>          
       		<td class="label" align="right" width="100px"><?php _resource('Assign to:') ?>
       		
       		</td>
       		<td align="left">
       			<?php 
        foreach($users as $k=>$v){
			$check='';
        	if($this->data[$uses[0]]['assignees']==$v['User']['id'])$check="checked=true";
			echo '<input '.$check.' type="radio" value="'.$v['User']['id'].'" id="'.$uses[0].$v['User']['id'].'" name="data['.$uses[0].'][assignees]" />
			<label for="'.$uses[0].$v['User']['id'].'">'.$v['User']['username'].'</label><br />';
		}
       			?>
       		</td>           
        </tr>   
        <?php }?>
        
        <?php if(isset($users)>0){?>
 	<tr>          
       		<td class="label" align="right" width="100px"><?php _resource('Add watch:') ?>
       		
       		</td>
       		<td align="left">
       			<?php
         foreach($users as $k=>$v){
        	$check='';
        	if($user['id']!=$v['User']['id'])
			echo '<input '.$check.' type="checkbox" value="'.$v['User']['id'].'" id="'.$uses[0].$v['User']['id'].'" name="data['.$uses[0].'][watches]['.$v['User']['id'].']" />
			<label for="'.$uses[0].$v['User']['id'].'">'.$v['User']['name'].'</label><br />';
		 }
       			
       
       			?>
       		</td>           
        </tr>   
        <?php }?>
        
        <?php if(isset($this->data['Field']) && count($this->data['Field'])>0){
        	foreach($this->data['Field'] as $k=>$v){
        	?>
        
 	<tr>          
       		<td class="label" align="right" width="100px"><?php _resource($this->data['Field'][$k]['name']) ?>
       		
       		</td>
       		<td align="left">
       			<?php 
       
			echo $this->Form->input('Field.'.$k.'.value',array('class'=>'input','label'=>'','size'=>60,'maxlength'=>255));
			echo $this->Form->hidden('Field.'.$k.'.name');
			echo $this->Form->hidden('Field.'.$k.'.id');
			echo $this->Form->hidden('Field.'.$k.'.field_id');

		
       			?>
       		</td>           
        </tr>   
        <?php }}?>
            
	</table>
	<center>
    <div style="width:130px">
          <div class="button"><a onclick="onFormSubmit()" href="javascript:;" title="<?php echo _resource('save') ?>"  > <span class="icon-32-save"> </span></a> </div>         
          <div class="button"><a onclick="resetForm('adminForm')" href="javascript:;" title="<?php echo _resource('reset') ?>"  > <span class="icon-32-back"> </span></a> </div>
          <div class="button"><a onclick="deactivateEditors();closeBox('addContent','mainContent')" href="javascript:;" title="<?php echo _resource('close') ?>"  > <span class="icon-32-cancel"> </span></a> </div>
    </div>
    </center>
      </form>
</fieldset>

<script>
function onFormSubmit(){
	deactivateEditors();
	submitForm('adminForm','addContent');
}
activateEditor("<?php echo $uses[0].'Description' ?>");
function removeFile(id){
	$('#'+id).remove();
}
swfu = new SWFUpload({	      
	// Backend Settings
	upload_url: "<?php echo BACKEND_URL.'fileuploads/imageupload/document/'.$uses[0]?>",
	post_params: {"PHPSESSID": "<?php echo session_id(); ?>"},

	// File Upload Settings
	/*
		file_size_limit: "100 KB" // kilobytes
		file_size_limit: "10000 b" // bytes
		file_size_limit: "25mb" // megabytes
		file_size_limit: "2 gb" // gigabytes
		file_size_limit: "342222" // kilobytes
	*/
	file_size_limit : "5 MB",
	file_types : "*.*",
	file_types_description : "All",
	file_upload_limit : 0,

	// Event Handler Settings - these functions as defined in Handlers.js
	//  The handlers are not part of SWFUpload but are part of my website and control how
	//  my website reacts to the SWFUpload events.
	swfupload_preload_handler : preLoad,
	swfupload_load_failed_handler : loadFailed,
	file_queue_error_handler : fileQueueError,
	file_dialog_complete_handler : fileDialogComplete,
	upload_progress_handler : uploadProgress,
	upload_error_handler : uploadError,
	upload_success_handler : uploadSuccess,
	upload_complete_handler : uploadComplete,

	// Button Settings
	//button_image_url : "<?php echo $this->webroot?>plugins/SWFUpload/images/SmallSpyGlassWithTransperancy_17x18.png",
	button_placeholder_id : "spanButtonPlaceholder",
	button_width: 107,
	button_height: 38,
	button_text : 'Browse',
	button_text_style : '.button { font-family: Helvetica, Arial, sans-serif; font-size: 12pt; } .buttonSmall { font-size: 10pt; }',
	button_text_top_padding: 0,
	button_text_left_padding: 18,
	button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
	button_cursor: SWFUpload.CURSOR.HAND,
	
	// Flash Settings
	flash_url : "<?php echo $this->webroot?>plugins/SWFUpload/js/swfupload.swf",
			flash9_url : "<?php echo $this->webroot?>plugins/SWFUpload/js/swfupload_fp9.swf",
    
	custom_settings : {					
		//upload_target : "divFileProgressContainer",//upload status
		type:3,//1: image, 2: gallery , 3: multi file
		uploadContainer:"divUploadContainer",// contain upload , use for multi upload				
		fieldName: "<?php echo 'data[FileAttach]'?>",
		numOfMaxUpload:0  //max of upload file, 1 for single, >1 for multi, 0 for unlimit
	},
	
	// Debug Settings
    debug: false

});
scrollTopTo('addContent');
</script>
<?php echo $this->element('sql_dump');?>
<?php } ?>
